package kaktus.jogl.helloworld;

import javax.media.opengl.awt.GLCanvas;
import javax.swing.event.MouseInputListener;
import java.awt.event.MouseEvent;



/**
 * Created with IntelliJ IDEA.
 * User: Admin
 * Date: 07.03.13
 * Time: 12:10
 * To change this template use File | Settings | File Templates.
 */
public class InputListener implements MouseInputListener {
    public Renderer r;
    public GLCanvas c;
    private float angle;

    public void setAngle(float a){
        angle=a;
    }
    public float getAngle(){
        return angle;
    }

    public float calcAngle(int x, int y ){
        float f;
        x = x - c.getWidth()/2;
        y = c.getHeight()/2 - y;
        f = (float)Math.atan((float)y/(float)x);
        if (x<0){
            return (float)(Math.PI+f);
        } else {
            return f;

        }
    }

    public InputListener(GLCanvas c1, Renderer r1){
        c = c1;
        r = r1;
        r.setAngle(angle);
    }

    public void mouseClicked(MouseEvent e) {
        r.setAngle(calcAngle(e.getX(),e.getY()));
    }

    public void mousePressed(MouseEvent e) {
        r.setAngle(calcAngle(e.getX(),e.getY()));

    }

    public void mouseReleased(MouseEvent e) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void mouseEntered(MouseEvent e) {
        //System.out.println("Entered " + e.getX() + " " + e.getY());
    }

    public void mouseExited(MouseEvent e) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void mouseDragged(MouseEvent e) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void mouseMoved(MouseEvent e) {
        r.setAngle(calcAngle(e.getX(), e.getY()));
    }
}
